<?php
namespace Admin\Controller;//命名空间 防止重名
use Think\Controller;//自动加载核心控制器类
class AdminController extends Controller {
    // 初始化 专门用来初始化的 在核心控制器调用完 构造方法后
    function _initialize()
    {
        if(!session('?cjl_uid')){
            $this->error('请先登录',U('Login/index'));exit;
        }

        //验证权限
        $this_menu['url'] = CONTROLLER_NAME.'/'.ACTION_NAME;
        $this_menu = M('Menu')->field('id')->where($this_menu)->select();
        if($this_menu){
            $pig = 0;
            foreach ($this_menu as $k => $v) {
               if(in_array($v['id'],session('cjl_pri'))){
                    $pig = 1;
               }
            }
            if(!$pig){
                $this->error('权限不足',U('Index/index'));exit;
            } 
        }
        // var_dump($this_menu);exit;

        $wh['id'] = array('in',implode(',', session('cjl_pri')));
        $wh['is_show'] = 1;
        $cjl_menu = M('Menu')->where($wh)->order('pid,sort,u_time desc,id desc')->select();

        $cjl_menu = get_category($cjl_menu,2);
        $this->assign('cjl_menu',$cjl_menu);
    }
    function __construct1()
    {
        parent::__construct();//重新调用父级构造方法
        if(!session('?cjl_uid')){
            $this->error('请先登录',U('Login/index'));exit;
        }
    }

    public function upload_one($width=192,$height=127){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,1); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
    public function upload_news_one($width=570,$height=304){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,1); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
    public function upload_er_one($width=118,$height=118){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,0); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
    public function upload_banner_one($width=1423,$height=326){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,1); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
    public function upload_about_one($width=458,$height=456){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,1); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
    public function upload_user_one($width=98,$height=98){
        // var_dump(666);
        // var_dump($_FILES);//拿到了图片
        $img['img'] = img_upload_one($_FILES['file'],$width,$height,3,0); //3代表居中裁剪
        $img['error'] = 0;
        $this->ajaxReturn($img);
    }
}